const readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})

let num1 = Math.floor((Math.random() * 10) + 1)
let num2 = Math.floor((Math.random() * 10) + 1)
let answer = num1 + num2

rl.question(`What is ${num1} + ${num2}? \n`,
  (userinput) => {
    if (userinput.trim() == answer) {
      console.log('Right! \n');
      rl.close()
    } else {

      // 设置提示信息，提示用户输入的答案不正确
      rl.setPrompt('Not Right! \n');

      //向用户显示提示符并等待用户输入
      rl.prompt()

      // 监听用户输入的每一行
      rl.on('line', (userinput) => {
        if (userinput.trim() == answer) {
          console.log('Right!! \n');
          rl.close()
        } else {
          rl.setPrompt('Not Right!! \n');
          rl.prompt()
        }
      })
    }
  })

rl.on('close', () => {
  console.log('The qustion was closed!!!!');
})